import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:hello_word/common/helper/resource_helper.dart';

class GuidePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _GuidePageState();
}

class _GuidePageState extends State<GuidePage> {
  static const List<String> images = <String>[
    'guide_page_1.png',
    'guide_page_2.png',
    'guide_page_3.png',
    'guide_page_4.png',
  ];

  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Theme.of(context).primaryColor,
        child: Stack(
          alignment: Alignment(0, 0.87),
          children: <Widget>[
            Swiper(
              itemBuilder: (context, index) {
                if (index % 2 == 1) {
                  return Image.asset(
                    ImageHelper.wrapAssets('splash_bg_dark.png'),
                    fit: BoxFit.fill,
                  );
                } else {
                  return Image.asset(
                    ImageHelper.wrapAssets('splash_bg_dark.png'),
                    fit: BoxFit.fill,
                  );
                }
              },
              itemCount: _GuidePageState.images.length,
              loop: false,
              onIndexChanged: (value) {
                setState(() {
                  currentIndex = value;
                  print(currentIndex);
                });
              },
            ),
            Offstage(
                offstage: currentIndex != _GuidePageState.images.length - 1,
                child: CupertinoButton(
                    color: Theme.of(context).primaryColor,
                    child: Text("点我开始"),
                    onPressed: () {
                      print("点击开始button");
                    })),
          ],
        ),
      ),
    );
  }
}
